<?php
// Load the QCubed Development Framework
require('../qcubed.inc.php');
require('panel/meetingHeaderPanel.class.php');
require('panel/meetingInfoPanel.class.php');
require('panel/MeetingNoteListPanel.class.php');
require('panel/MeetingNoteEditPanel.class.php');
require('panel/MeetingNoteInfoPanel.class.php');


class MeetingEditForm extends QForm {
    protected $mctMeeting;
    protected $objMeeting;

    public $tabMain;
    protected $pnlHeader;
    protected $pnlNotes;

    protected $pnlInfo;

    protected $pnlNoteList;
    protected $pnlNoteEdit;
    protected $pnlNoteInfo;


    protected $btnSave;
    protected $btnCancel;
    // Override Form Event Handlers as Needed
//		protected function Form_Run() {}

//		protected function Form_Load() {}

//		protected function Form_Create() {}
    protected function Form_Run() {
        QApplication::CheckRemoteAdmin();
    }

    public function PersonOrg_Change($strParameter) {
        $objMemberArray = Person::QueryArray(
                QQ::AndCondition(
                QQ::OrCondition(
                QQ::Equal(QQN::Person()->Org, 1 ),
                QQ::Equal(QQN::Person()->Org, 2 )
                ),
                QQ::OrCondition(
                QQ::Like(QQN::Person()->FirstName, $strParameter . '%'),
                QQ::Like(QQN::Person()->LastName, $strParameter . '%')
                )
                ),
                QQ::Clause(QQ::OrderBy(QQN::Person()->FirstName))

        );
        $result = array();
        foreach($objMemberArray as $objMember) {
            $result[] = $objMember->FirstName .  " ".  $objMember->LastName . "|" . $objMember->Id ;
        }
        return $result;
    }

    protected function Form_Create() {
        //$this->mctMeeting = MeetingMetaControl::CreateFromPathInfo($this) ;
        //$this->objPerson= $this->mctPerson->__get("Person");

        $this->mctMeeting = MeetingMetaControl::CreateFromPathInfo( $this );
        $this->objMeeting = $this->mctMeeting->__get("Meeting");

        $this->tabMain = new JTab("MainTab");

        $this->pnlHeader = new MeetingHeaderPanel($this,"SetEditPane", $this->mctMeeting);


        $this->pnlNotes = new QePanel($this);
        $this->pnlNotes->AutoRenderChildren = true;
        //tab List All
        $this->tabMain->AddTab(QApplication::Translate("Header"),$this->pnlHeader );

        $this->tabMain->AddTab(QApplication::Translate("Notes"));

        $blnEdit= $this->mctMeeting->__get("EditMode");
        if ($blnEdit) {
            $_SESSION['MeetingId'] = $this->objMeeting->Id;
            $this->pnlNoteList = new MeetingNoteListPanel($this,"");
        }
        else
            $this->pnlNoteList = New QePanel($this);



        $this->pnlNoteEdit = New QePanel($this);
        $this->pnlNoteInfo = New QePanel($this);


        $this->tabMain->AddTab(QApplication::Translate("List Notes"),$this->pnlNoteList, QApplication::Translate("Notes"));

        $this->tabMain->AddTab(QApplication::Translate("Edit Notes"), $this->pnlNoteEdit, QApplication::Translate("Notes"));


        $this->tabMain->AddTab(QApplication::Translate("Record Info"),$this->pnlNoteInfo, QApplication::Translate("Notes"));

        $this->pnlInfo = New MeetingInfoPanel($this,$this->mctMeeting );
        $this->tabMain->AddTab(QApplication::Translate("Records Info"), $this->pnlInfo);

    }


    public function ClosePanel($ClosePanel, $RefreshPanel=null) {
        $this->$ClosePanel->RemoveChildControls(true);
        $this->$ClosePanel->Visible = false;

        if ($RefreshPanel)
            $this->$RefreshPanel->Refresh();
    }

    public function SetEditPanel($objPanel , $objParent) {
        $this->$objParent->RemoveChildControls(true);
        $this->$objParent->AutoRenderChildren= true;
        if ($objPanel) {
            $objPanel->SetParentControl($this->$objParent);
            $this->$objParent->Visible = true;

        } else {
            $this->$objParent->Visible = false;

        }
        //$this->tabMain->ChangeTabById(1);
    }

    public function strTruncate($string, $length) {
        $output="";
        settype($string, 'string');
        settype($length, 'integer');
        for($a = 0; $a < $length AND $a < strlen($string); $a++) {
            $output .= $string[$a];
        }
        return($output);
    }



}


MeetingEditForm::Run('MeetingEditForm','tpl/meeting_edit.tpl.php');
?>